package com.markhsiu.MiniMQ.broker.factory;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import com.markhsiu.MiniMQ.broker.task.MessagePushTask;
import com.markhsiu.MiniMQ.remote.Server;
import com.markhsiu.MiniMQ.remote.transport.netty.NettyServer;

public class Broker {

	private Server server;
	
	private ExecutorService pool =  Executors.newCachedThreadPool();
	
	public void start(){
		server = new NettyServer();
		try {
			server.open();
		} catch(Exception e) {
			server.close();
			e.printStackTrace();
		}     
	}
	
	public void  init(){
		pool.submit(new MessagePushTask());
	}
	
	public void shutdown(){
		server.close();
	}
}
